package com.enqualcomm.kids.mvp.bindphoneaccount;

import com.android.volley.VolleyError;
import com.enqualcomm.kids.R;
import com.enqualcomm.kids.mvp.NetworkModel;
import com.enqualcomm.kids.network.NetworkListener;
import com.enqualcomm.kids.network.SocketRequest;
import com.enqualcomm.kids.network.socket.request.BindUserRelationParams;
import com.enqualcomm.kids.network.socket.request.BindUserRelationSetParams;
import com.enqualcomm.kids.network.socket.response.BasicResult;
import com.enqualcomm.kids.network.socket.response.BindUserRelationSetResult;
import com.enqualcomm.kids.network.socket.response.LoginOtherResult;

/**
 * Created by Sunzhigang on 2016/9/14.
 */
public class BindModelImpl extends NetworkModel implements Bindmodel {
    @Override
    public void bindPhoneAccount(String userid, String userkey, String unnid, String country, String phone, String userpwd, final onBindPhoneAccountListener listener) {
        BindUserRelationSetParams params = new BindUserRelationSetParams(userid, userkey, unnid, country, phone, userpwd);
        loadDataFromServer(new SocketRequest<LoginOtherResult>(params, new NetworkListener<LoginOtherResult>() {
            @Override
            public void onError(VolleyError error) {
                listener.failed(R.string.network_error);
            }

            @Override
            public void onSuccess(LoginOtherResult response) {
                if (response.code == 0) {
                    listener.success(response);
                } else {
                    listener.failed(response.desc);
                }
            }
        }));
    }
}
